package com.xmkj.bearbiz.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.methods.CancleOrderMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.xmkj.bearbiz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/4/7.
 */

public class OrderInfoActivity extends BaseMvpActivity {
    public static final String ISNOW = "isnow";
    public static final String ORDERIDBEAN = "orderIdBean";
    public static final String LONGITUDE = "LONGITUDE";
    public static final String LATITUDU = "LATITUDU";
    public static final String REALLADRESS = "REALLADRESS";
    @BindView(R.id.tv_state)
    TextView tvState;
    @BindView(R.id.tv_info)
    TextView tvInfo;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_check_location)
    TextView tvCheckLocation;
    private int type;
    private int orderId;
    private String latitudu;
    private String longitude;
    private String realladress;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_info;
    }

    @Override
    protected void onViewCreated() {
        type = getIntent().getIntExtra(ISNOW, 0);
        latitudu = getIntent().getStringExtra(LATITUDU);
        longitude = getIntent().getStringExtra(LONGITUDE);
        realladress = getIntent().getStringExtra(REALLADRESS);
    }

    @Override
    protected void doLogicFunc() {
        if (type == 1) {
            tvState.setText("您已下单成功");
            tvInfo.setText("洗车人正在来的路上 您稍等片刻哦~");

        } else if (type == 2) {
            tvState.setText("您已预约成功");
            tvInfo.setText("洗车人会在预约时间内 到达指定地点~");
            tvCheckLocation.setVisibility(View.GONE);
        }
        attachClickListener(ivBack);
        attachClickListener(tvCancel);
        attachClickListener(tvCheckLocation);
    }

    @Override
    protected void onViewClicked(View view) {
        if (ivBack.getId() == view.getId()) {
            onBackPressed();
        } else if (tvCancel.getId() == view.getId()) {
            showTwoDialog("提示", "您确定要取消订单么？服务人员已经在来的路上了.....", "确定", "取消");
            setOnDialogViewClick(new OnDialogViewClick() {
                @Override
                public void leftViewClick() {
//                        showToastMsg("hha");
                    gotoCancleOrder();
                }

                @Override
                public void singleViewClick() {

                }
            });
        } else if (tvCheckLocation.getId() == view.getId()) {
//            gotoActivity(MapDetailActivity.class);
            Intent intent = new Intent(context,MapLocationActivity.class);
            intent.putExtra(MapLocationActivity.LATITUDU,latitudu);
            intent.putExtra(MapLocationActivity.LONGITUDE,longitude);
            intent.putExtra(MapLocationActivity.REALLADRESS,realladress);
            startActivity(intent);
        }
    }

    private void gotoCancleOrder() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();
                onBackPressed();
            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });
        CancleOrderMethods.getInstance().cancelOrder(subscriber, uid, hashid, orderId);
        rxManager.add(subscriber);
    }

    @Override
    protected void setNavigation() {
        type = getIntent().getIntExtra(ISNOW, 0);
        orderId = getIntent().getIntExtra(ORDERIDBEAN, 0);
        if (type == 1) {
            setNavigationBack("派单成功");
        } else if (type == 2) {
            setNavigationBack("预约成功");
        }
    }

    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }
}
